package com.film.controller.movie;

import com.alibaba.fastjson.JSONObject;
import com.film.jwt.JwtUtil;
import com.film.service.impl.movie.DeleteMovieByIdServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;

//根据电影id删除电影（该id在之前电影被拉取时会发送给前端）
@RestController
public class DeleteMovieByIdController {
    @Autowired
    private DeleteMovieByIdServiceImpl deleteMovieByIdService;

    @PostMapping("/movie/delete/{movieId}/{token}")
    public JSONObject delete(@PathVariable Integer movieId, @PathVariable String token) throws SQLException {
        if (!JwtUtil.JwtVerify(token)) {
            JSONObject resp = new JSONObject();
            resp.put("error_message", "jwt验证错误");
            return resp;
        } else {
            return deleteMovieByIdService.delete(movieId);
        }
    }
}
